﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once

#include "GmFamilyService.h"

#include "IGraphicsNodeReference.h"
#include "Vector3d.h"
#include "FamilyConstraintReferenceType.h"
#include "FamilySolverResult.h"


namespace gcmp
{
    class IDocument;
    class IElement;
}

namespace gfam
{
    class IFamilySketch;
    class IFamilyConstraint;

    
    /// \brief 约束解算工具类
    class GM_FAMILY_SERVICE_EXPORT FamilySolverUtils
    {
    public:

        /// \brief 动态解算
        /// 
        /// \param pDocument 文档
        /// \param pDragElement 拖拽对象
        /// \param referenceType 约束对象引用类型
        /// \param moveOrigin 起点
        /// \param moveDelta 偏移量
        /// \param checkData 约束解算后是否检查实体数据，比如拖拽拉伸体夹点会导致拉伸体轮廓草图自交
        /// \return 解算结果
        static FamilySolverResult DynamicSolve(gcmp::IDocument* pDocument,gcmp::IElement* pDragElement, FamilyConstraintReferenceType referenceType,
            const gcmp::Vector3d& moveOrigin,const gcmp::Vector3d& moveDelta, bool checkData = false);

        /// \brief 解算文档
        /// 
        /// \param pDocument 文档
        /// \param pFailedConstraints 引起解算失败的约束集合
        /// \return 解算结果
        static FamilySolverResult SolveDocument(gcmp::IDocument* pDocument,std::set<const gfam::IFamilyConstraint*>* pFailedConstraints = nullptr);


        /// \brief 解算草图或文档
        /// 
        /// \param pDocument 文档
        /// \param pFamilySketch 草图
        /// \param failedConstraints 引起解算失败的约束集合
        /// \return 解算结果
        static FamilySolverResult SolveSketchOrDocument(gcmp::IDocument* pDocument, IFamilySketch* pFamilySketch = nullptr, std::set<const gfam::IFamilyConstraint*>* failedConstraints = nullptr);


        /// \brief 获取解算结果字符串
        /// 
        /// \param solverResult 解算结果
        /// \return 输出字符串
        static const std::wstring GetSolverResultString(const gfam::FamilySolverResult solveResult);


        /// \brief 验证文档中所有约束的有效性
        /// 
        /// \param pDocument 文档
        /// \return 有效返回true；否则返回false
        static Bool ValidateConstraints(const gcmp::IDocument* pDocument);

    };
}

